package com.trevor.services;

import java.util.ArrayList;
import java.util.HashMap;

import com.trevor.domain.User;
import com.trevor.utils.SqlUtil;

public class InformService {
	public HashMap<String,ArrayList> getInformation(User u,String po){
		String courses[]=u.getCourses();
		String courseNum=courses[Integer.parseInt(po)];
		SqlUtil su=new SqlUtil();
		String paras[];
		String sql1="select * from anounce1 order by posttime desc;";
		String sql2="select * from comments1 order by posttime desc;";
		String sql3="select * from datas1 order by dataid;";
		ArrayList anounces=su.executeQuery(sql1, null);
		ArrayList comments=su.executeQuery(sql2, null);
		ArrayList datas=su.executeQuery(sql3, null);
		HashMap<String, ArrayList> info=new HashMap<String, ArrayList>();
		info.put("anounces", anounces);
		info.put("comments",comments);
		info.put("datas", datas);
		return info;
	}
	public String getCourseName(User u,String po){
		String courses[]=u.getCourses();
		LoginService ls=new LoginService();
		String courseName[]=ls.courseToCn(courses);
		return courseName[Integer.parseInt(po)];
	}
	public String getDownAdress(String dataid){
		SqlUtil su=new SqlUtil();
		String sql1="select * from datas1 where dataid=?;";
		String[] paras={dataid};
		ArrayList data=su.executeQuery(sql1, paras);
		Object[] address=(Object[]) data.get(0);
		System.out.println(address[1].toString());
		return address[1].toString();
		
	}
	public String getDownName(String dataid) {
		// TODO Auto-generated method stub
		SqlUtil su=new SqlUtil();
		String sql1="select * from datas1 where dataid=?;";
		String[] paras={dataid};
		ArrayList data=su.executeQuery(sql1, paras);
		Object[] address=(Object[]) data.get(0);
		System.out.println(address[2].toString());
		return address[2].toString();
	}
}
